#ifndef RENDERER_H
#define RENDERER_H

#include "EngineApi.h"
#include "Window.h"
#include "Struct.h"
#include "VertexBuffer.h"
#include "Vector3.h"
#include "Texture.h"

#include <d3d9.h>
#include <d3dx9.h>
#include <d3dx9math.h>
#include <map>


class ENGINE_API Renderer
{
public:
   Renderer();

   bool init(HWND hwnd);
   void clear(short red = 0, short green = 0, short blue = 0);
   void beginFrame();
   void endFrame();
   void present(HWND hwnd);
   void deInit();

   bool DrawElements(USHORT vertexCount, ColorVertex* vertices, USHORT primCount, PRIM_TYPE primType);
   bool DrawElements(USHORT vertexCount, TextureVertex* vertices, USHORT primCount, PRIM_TYPE primType);

   LPDIRECT3DDEVICE9 getDevice() { return m_dxDevice; }

   void setMatrixMode(MatrixMode mMode);
   void loadIdentity();

   void Translate(Vector3 translation);
   
   void RotateX(float angle);
   void RotateY(float angle);
   void RotateZ(float angle);
   
   void Scale(Vector3 scale);

   bool bindTexture(Texture::TexturePtr texture);
   void unbindTexture();
   bool loadTexture(const char* filename, Texture::TexturePtr texture);

protected:
   std::map<std::string, IDirect3DTexture9*> m_D3DTextureMap;

private:
   LPDIRECT3D9 m_dxObject;
   LPDIRECT3DDEVICE9 m_dxDevice;

   VertexBuffer<ColorVertex, FVF_COLORVERTEX> m_vertexBuffer;
   VertexBuffer<TextureVertex, FVF_TEXTUREVERTEX> m_textureVertexBuffer;

   D3DTRANSFORMSTATETYPE m_currentMatrixMode;

};
#endif//RENDERER_H